package class0224

import scala.io.StdIn._

object PrimeFactorization {
  def primeFactors(n: Int): List[Int] = {
    def factors(n: Int, divisor: Int): List[Int] = {
      if (divisor * divisor > n) {
        if (n > 1) List(n) else List()
      } else {
        if (n % divisor == 0) {
          divisor :: factors(n / divisor, divisor)
        } else {
          factors(n, divisor + 1)
        }
      }
    }

    factors(n, 2)
  }

  def main(args: Array[String]): Unit = {
    // 让用户输入一个正整数
    println("请输入一个正整数:")
    val number = readInt()  // 读取输入的整数

    // 计算并打印质因数
    val factors = primeFactors(number)
    println(s"$number = ${factors.mkString("*")}")
  }
}
